const query = require('../model/index')
const { getLocalIP } = require('../utils/getIP')
const config = require('../config.js')
const ip = getLocalIP()
// console.log('获取ip',getLocalIP())

/**
 * @func upload
 * @desc 上传文件
 * @param {file}  file
 * @return {}
 */
exports.upload = async (req, res, next) => {
  console.log('是否生产',config.isProduct);
  const { filename, path, mimetype, size } = req.file
  // const { hostname } = req
  // console.log('文件流', req.file)
  // console.log(req)
  // const newPath = path.replace(/\\/g,'/')

  const info = {
    imgUrl: `${ip}/imgs/${filename}`,
    name: filename,
    type: mimetype,
    size,
  }

  if (path) res.cc('success', 0, info)
  else res.cc('上传失败', 999999, null)
}
